home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Voyeur 1.1.1 / Voyeur ƒ / MSG Shell ƒ / msg apple events.c < prev    next >
Text File  |  1994-02-24  |  3KB  |  130 lines

  1. /**********************************************************************\
  2.  
  3. File:        msg apple events.c
  4.  
  5. Purpose:    This module handles the 4 required apple events: open
  6.             application, open document, print document (not supported),
  7.             and quit application.
  8.  
  9.  
  10. Voyeur -- a no-frills file viewer
  11. Copyright ©1993-4, Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "msg apple events.h"
  31. #include "msg environment.h"
  32. #include "v generic open.h"
  33.  
  34. void SetUpAppleEvents(void)
  35. {
  36.     AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
  37.                                     HandleOpenAppAE, 0, FALSE);
  38.     AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
  39.                                     HandleOpenDocAE, 0, FALSE);
  40.     AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
  41.                                     HandlePrintDocAE, 0, FALSE);
  42.     AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
  43.                                     HandleQuitAE, 0, FALSE);
  44.     AESetInteractionAllowed(kAEInteractWithAll);
  45. }
  46.  
  47. pascal OSErr HandleOpenAppAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  48.     long refcon)
  49. {
  50.     return MyGotRequiredParams(theAppleEvent);
  51. }
  52.  
  53. pascal OSErr HandleOpenDocAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  54.     long refcon)
  55. {
  56.     OSErr            isHuman, dummy;
  57.     FSSpec            myFSS;
  58.     AEDescList        docList;
  59.     long            index, itemsInList;
  60.     Size            actualSize;
  61.     AEKeyword        keywd;
  62.     DescType        returnedType;
  63.     
  64.     isHuman=AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
  65.     if (isHuman==noErr)
  66.     {
  67.         if (MyGotRequiredParams(theAppleEvent)==noErr)
  68.         {
  69.             if (AECountItems(&docList, &itemsInList)==noErr)
  70.             {
  71.                 for (index=1; index<=itemsInList; index++)
  72.                 {
  73.                     if (AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType,
  74.                         &myFSS, sizeof(myFSS), &actualSize)==noErr)
  75.                     {
  76.                         GenericOpen(&myFSS);
  77.                     }
  78.                     else
  79.                     {
  80.                         // handle error getting Nth pointer
  81.                     }
  82.                 }
  83.             }
  84.             else
  85.             {
  86.                 // handle error counting items
  87.             }
  88.         }
  89.         else
  90.         {
  91.             // handle error from MyGetRequiredParams
  92.             dummy=AEDisposeDesc(&docList);
  93.         }
  94.     }
  95.     else
  96.     {
  97.         // handle error getting direct parameter
  98.     }
  99.     
  100.     return isHuman;
  101. }
  102.  
  103. pascal OSErr HandlePrintDocAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  104.     long refcon)
  105. {
  106.     return errAEEventNotHandled;
  107. }
  108.  
  109. pascal OSErr HandleQuitAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  110.     long refcon)
  111. {
  112.     OSErr            isHuman;
  113.     
  114.     isHuman=MyGotRequiredParams(theAppleEvent);
  115.     if (isHuman==noErr)
  116.         gDone = 1;
  117.     
  118.     return isHuman;
  119. }
  120.  
  121. pascal OSErr MyGotRequiredParams(const AppleEvent *theAppleEvent)
  122. {
  123.     DescType        returnedType;
  124.     Size            actualSize;
  125.     
  126.     return (AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  127.             &returnedType, 0L, 0, &actualSize)==errAEDescNotFound) ? noErr :
  128.             errAEParamMissed;
  129. }
  130.